//
//  XMGEssenceViewController.m
//  BuDeJie19
//
//  Created by hjj on 2016/12/3.
//  Copyright © 2016年 hjjuny. All rights reserved.
//

#import "XMGEssenceViewController.h"
#import "UIBarButtonItem+Item.h"
#import "XMGAllViewController.h"
#import "XMGVideoViewController.h"
#import "XMGVoiceViewController.h"
#import "XMGPictureViewController.h"
#import "XMGTextViewController.h"

#import "XMGBaseTopiceViewController.h"
/*
 离屏渲染：当一个View不管有没有显示，只要添加到窗口上，就会被渲染.
 
 精华搭建方案：UIScrollView + UICollectionView
 
 如果把A控制器的View添加到B控制器的View上，那么A控制器必须要成为B控制器的子控制器
 */

/*
 iOS7之后，导航控制器只会给它里面的一个ScrollView顶部添加额外滚动区域。
 */


@interface XMGEssenceViewController ()

@end

@implementation XMGEssenceViewController

// super:让当前对象调用父类方法
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self setupNavBar];
    
    // 添加所有的子控制器:
    [self setupAllChildViewController];
}

- (void)setupAllChildViewController
{
    // 全部
    XMGBaseTopiceViewController *allVc = [[XMGBaseTopiceViewController alloc] init];
    allVc.title = @"全部";
    allVc.type = @(XMGTopicItemTypeAll);
    [self addChildViewController:allVc];
    
    // 视频
    XMGBaseTopiceViewController *videoVc = [[XMGBaseTopiceViewController alloc] init];
    videoVc.title = @"视频";
    videoVc.type = @(XMGTopicItemTypeVideo);
    [self addChildViewController:videoVc];
    
    // 声音
    XMGBaseTopiceViewController *voiceVc = [[XMGBaseTopiceViewController alloc] init];
    voiceVc.title = @"声音";
    voiceVc.type = @(XMGTopicItemTypeVocie);
    [self addChildViewController:voiceVc];
    
    // 图片
    XMGBaseTopiceViewController *pictureVc = [[XMGBaseTopiceViewController alloc] init];
    pictureVc.title = @"图片";
    pictureVc.type = @(XMGTopicItemTypePicture);
    [self addChildViewController:pictureVc];
    
    // 段子
    XMGBaseTopiceViewController *textVc = [[XMGBaseTopiceViewController alloc] init];
    textVc.type = @(XMGTopicItemTypeText);
    textVc.title = @"段子";
    [self addChildViewController:textVc];
}

- (void)setupNavBar
{
    // 设置导航条内容 => 栈顶控制器的navgationItem决定
    self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"MainTitle"]];
    
    // bug:按钮点击范围扩大
    // 不要让按钮扩大点击范围
    // 把按钮包装成UIBarButtonItem就让按钮扩大点击范围
    
    // 左边
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImage:[UIImage imageNamed:@"nav_item_game_icon"] highImage:[UIImage imageNamed:@"nav_item_game_click_icon"] target:self action:@selector(gameClick)];
    
    // 右边
    UIBarButtonItem *item = [UIBarButtonItem itemWithImage:[UIImage imageNamed:@"navigationButtonRandom"] highImage:[UIImage imageNamed:@"navigationButtonRandomClick"] target:nil action:nil];
    self.navigationItem.rightBarButtonItem = item;
}

- (void)gameClick
{
    NSLog(@"点击了游戏");
}


@end
